package com.blog.controller;

import com.blog.Utils.Result;
import com.blog.annotion.LoginAnnotatio;
import com.blog.bean.domain.Note;
import com.blog.bean.dto.NoteDTO;
import com.blog.service.NoteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;
import java.util.Objects;

/**
 * @author 任浩
 * @version 1.0
 */

@RestController
@RequestMapping("/note")
public class NoteController {

    @Autowired
    private NoteService noteService;

    /**
     * 根据条件查询笔记列表。
     * @return
     */
    @LoginAnnotatio
    @GetMapping("/getNote")
    public Result<Map<String, Object>> getNote(@RequestParam(name = "startTime",required = false) String startTime,
                                                @RequestParam(name = "endTime",required = false) String endTime,
                                                @RequestParam(name = "type",required = false) String type,
                                                @RequestParam(name = "title",required = false) String title,
                                                @RequestParam(name = "size",required = true) Integer size,
                                                @RequestParam(name = "page",required = true) Integer page){
        return Result.success(noteService.getNote(startTime,endTime,type,title,size,page));
    }


    /**
     * 编辑笔记功能，可以是(新增或者更新)
     * @param noteDTO
     * @return
     */
    @LoginAnnotatio
    @PostMapping("/editNote")
    public Result editNote(@RequestBody NoteDTO noteDTO){
        Result res = noteService.editNote(noteDTO);
        return res;
    }

    /**
     *  删除笔记的操作。
     * @param ids
     * @return
     */
    @LoginAnnotatio
    @PostMapping("/delete")
    public Result deleteNote(@RequestBody List<Integer> ids){
        return noteService.deleteNote(ids);
    }


}
